package com.xjtu.platform.security.login;

import com.xjtu.platform.common.Result;
import com.xjtu.platform.common.TokenUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @创建人 MBY381
 * @创建时间 2022/6/29 11:38
 * @描述 暂无
 */


@RestController
@RequestMapping("/security/login")
public class LoginAPI {

    @Resource
    private LoginService loginService;

    @PostMapping("")
    public Result Login(@RequestBody LoginDto dto){
        boolean ok = loginService.checkLogin(dto);

        if(ok){
            boolean mailComplete = loginService.checkEmail(dto.getUser_id());
            System.out.println(mailComplete);
            if(!mailComplete){
                return Result.success("请完善邮箱！！！","flag");
            }
            String role_web = loginService.findWeb(dto);

            String token = TokenUtils.loginSign(dto.getUser_id(),dto.getUser_pwd());
            return Result.success(role_web,(Object)token);
        }

        return Result.fail(Result.ERR_CODE_BUSINESS,"账号或者密码错误");
    }
}
